package zelix.gui.clickguis.kendall.components.impls;

import zelix.gui.clickguis.N3ro.Utils.RenderUtil;
import zelix.gui.clickguis.kendall.components.Component;
import zelix.gui.clickguis.kendall.frame.KendallFrame;
import zelix.hack.Hack;
import zelix.hack.hacks.ClickGui;
import zelix.utils.Wrapper;
import zelix.utils.hooks.visual.ColorUtils;
import zelix.utils.hooks.visual.font.FontLoaders;
import zelix.value.BooleanValue;
import zelix.value.ModeValue;
import zelix.value.NumberValue;
import zelix.value.Value;

import javax.xml.crypto.dsig.keyinfo.KeyValue;
import java.awt.*;
import java.util.ArrayList;

import static zelix.gui.clickguis.kendall.frame.KendallFrame.isHovered;

public class KendallButton {
    public float x;
    public float y;
    public boolean showSettings;
    public Hack mod;
    public KendallFrame parent;
    public static int drawColor;

    public Color color = new Color(0xFFFFFFFF);
    public ArrayList<Component> components = new ArrayList<Component>();
    public KendallKeyBind kendallKeyBind;

    public KendallButton(Hack cheat, float x, float y, KendallFrame parent){
        this.x = x;
        this.y = y;
        this.mod = cheat;
        this.parent = parent;
        kendallKeyBind = new KendallKeyBind(cheat,this);
        this.init();
    }
    public void init(){

        components.clear();
        components.add(kendallKeyBind);
        for (Value v:this.mod.getValues()) {
            if (v instanceof BooleanValue){
                components.add(new KendallOption((BooleanValue)v,this));
            }
            if (v instanceof NumberValue){
                components.add(new KendallSIlder((NumberValue)v,this));
            }
            if (v instanceof ModeValue){
                components.add(new KendallMode((ModeValue)v,this));
            }
        }


    }

    int r1 = new Color(0xFFFFFFFF).getRed();
    int r2 = new Color(0xFF0079BD).getRed();
    public int task = 10;
    int i = 0;
    public void onRender(int mouseX, int mouseY,boolean last) {
        //y-4/2
        this.x = parent.x;
        //0xFF111111
        /*
        int Ver = 0;
        int dz=0;

        if(r1>r2){
            Ver=-1;
        }else{
            Ver=1;
        }

        i++;
        if(r1 + i*Ver > 255){
            r1 = 255;
        }else if(r1 + i*Ver < 255){
            r1 = 0;
        }else{
            r1 = r1 + i*Ver;
        }

         */


        color = new Color(r1,color.getGreen(),color.getBlue());
        if(this.mod.isToggled()){
            if (last){
                RenderUtil.drawRoundRect_down((double)this.x,(double)this.y,(double)this.x +100,(double)this.y+18, 2, ColorUtils.rainbow(task));
            }else{
                RenderUtil.drawBorderedRect(this.x,this.y,this.x +100,this.y+18, 0,0, ColorUtils.rainbow(task));
            }
            if (!ClickGui.language.getMode("Chinese").isToggled()){
                FontLoaders.default14.drawStringWithShadow(this.mod.getRenderName(), this.x +10,this.y+7, new Color(drawColor).getRGB());
            }else{
                Wrapper.INSTANCE.fontRenderer().drawStringWithShadow(this.mod.getRenderName(), this.x +10,this.y+5, new Color(drawColor).getRGB());
            }

        }else{
            if (last){
                RenderUtil.drawRoundRect_down((double)this.x,(double)this.y,(double)this.x +100,(double)this.y+18, 2,isButtonHovered(this.x,this.y,this.x +90,this.y+16,mouseX,mouseY)? 0xFF1D1D1F:0xFF161616);
            }else{
                RenderUtil.drawBorderedRect(this.x,this.y,this.x +100,this.y+18, 0,0, isButtonHovered(this.x,this.y,this.x +90,this.y+16,mouseX,mouseY)? 0xFF1D1D1F:0xFF161616);
            }
            if (!ClickGui.language.getMode("Chinese").isToggled()){
                FontLoaders.default14.drawStringWithShadow(this.mod.getRenderName(), this.x +10,this.y+7, 0xCCFFFFFF);
            }else{
                Wrapper.INSTANCE.fontRenderer().drawStringWithShadow(this.mod.getRenderName(), this.x +10,this.y+5, new Color(drawColor).getRGB());
            }

        }
        



    }
    public void onClick(int mouseX, int mouseY,int mouseButton) {
        System.out.println("x,u = "+mouseButton);
        if (mouseButton == 0 && isButtonHovered(this.x,this.y,this.x +90,this.y+16,mouseX,mouseY)){
            this.mod.setToggled(!this.mod.isToggled());
        }
        if (mouseButton == 1 && isHovered(this.x,this.y,this.x +90,this.y+16,mouseX,mouseY)){

            ClickGui.KendallMyGod.isVIsableSW = true;
            ClickGui.KendallMyGod.targetbt = this;
        }
    }

    public static boolean isButtonHovered(float f, float y, float g, float y2, int mouseX, int mouseY) {
        if (mouseX >= f && mouseX <= g && mouseY >= y && mouseY <= y2) {
            return true;
        }
        return false;
    }


}
